package com.example.appointment.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.example.appointment.R;

import butterknife.Bind;

/**
 * 个人签名的界面
 */
public class EditSignatureActivity extends BaseActivity {
    @Bind(R.id.activity_editsignature_edit)
    EditText editsignature;
    @Bind(R.id.activity_editsignature_hinttext)
    TextView hinttext;
    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {

            }
        }
    };

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
                case 0x111:
                    break;
            }
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setnotificationColore(R.color.maincolor);//設置导航栏顔色
        setContentView(R.layout.activity_editsignature);
        initView();

    }

    /**
     *
     */
    private void initView() {
        setTitile("个人签名");
        //设置保存按钮的功能
        getSavebtn().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setResult(RESULT_OK, new Intent().putExtra("signature", editsignature.getText().toString()));
                EditSignatureActivity.this.finish();
            }
        });
        editsignature.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (s.toString().length() > 50) {
                    editsignature.setText(s.subSequence(0, 50));
                    editsignature.setSelection(50);
                } else {

                    hinttext.setText(s.toString().length() + "/" + "50");

                }
            }
        });
    }


}
